package com.lcb.order.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lcb.common.utils.BaseApiService;
import com.lcb.common.utils.BaseResponse;
import com.lcb.order.entity.UndoLog;
import com.lcb.order.mapper.UndoLogMapper;
import com.lcb.order.service.UndoLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;

import java.util.Arrays;

/****
 * @Author:lcb
 * @Description:UndoLog业务层接口实现类
 * @Date: 2021-01-28 11:24:59
 *****/

@RestController
//@RequestMapping("/order")
//@CrossOrigin
public class UndoLogServiceImpl extends BaseApiService implements UndoLogService {

    @Autowired
    private UndoLogMapper undoLogMapper;

    /**
     * UndoLog条件+分页查询
     * @param undoLog 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public BaseResponse findUndoLogList(@RequestBody UndoLog undoLog, @PathVariable(value = "page") int page, @PathVariable(value = "size") int size){
        //分页
        PageHelper.startPage(page,size);

        PageInfo<UndoLog> pagelist =new PageInfo<UndoLog>(undoLogMapper.select(undoLog));

        return setResultSuccess(pagelist);
    }

    /**
     * 删除
     * @param ids
     */
    @Override
    public BaseResponse deleteUndoLogById (@PathVariable(value = "ids") String ids){

        String[] split = ids.split(",");
        Example example = new Example(UndoLog.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIn("id", Arrays.asList(split));
        undoLogMapper.deleteByExample(example);
        return setResultSuccess("删除成功");
    }

    /**
     * 修改UndoLog
     * @param undoLog
     */
    @Override
    public BaseResponse updateUndoLog(@RequestBody UndoLog undoLog){
        undoLogMapper.updateByPrimaryKeySelective(undoLog);
        return setResultSuccess("修改成功");
    }

    /**
     * 增加UndoLog
     * @param undoLog
     */
    @Override
    public BaseResponse addUndoLog(@RequestBody UndoLog undoLog){
        undoLogMapper.insertSelective(undoLog);
        return setResultSuccess("添加成功");
    }

    /**
     * 根据ID查询UndoLog
     * @param id
     * @return
     */
    @Override
    public BaseResponse findUndoLogById(@PathVariable(value = "id") Long id){
        return setResultSuccess( undoLogMapper.selectByPrimaryKey(id));
    }

    /**
     * 查询UndoLog全部数据
     * @return
     */
    @Override
    public BaseResponse findUndoLogAll() {
        return setResultSuccess(undoLogMapper.selectAll());
    }
}
